#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdint.h>
struct ListNode {
    int val;
    struct ListNode* next;
    
};
typedef struct ListNode ListNode;

int lengthOfLongestSubstring(char* s) {
    int len = strlen(s);
    int i = 0, j = 0;
    int max = 0;
    int tmp = 0;
    int left = 0, right = 0;
    int flag = 0;
    for (i = 0; i < len; i++)
    {
        if (left <= right)
        {
            flag = 0;
            for (j = left; j < right; j++)
            {
                if (s[j] == s[right])
                {
                    flag = 1;
                    break;
                }
            }
            if (flag)
            {
                left = j + 1;
            }
        }

        tmp = right - left + 1;
        if (max < tmp)
        {
            max = tmp;
        }
        right++;
    }
    return max;
}

int findMaxConsecutiveOnes(int* nums, int numsSize) {
    int left = 0, right = 0;
    int flag = 0;
    int i = 0, j = 0;
    int max = 0;
    for (i = 0; i < numsSize; i++)
    {
        if (left <= right)
        {
            if (nums[right] == 0)
            {
                left = right + 1;
            }
        }
        if (max < (right - left + 1))
            max = right - left + 1;
        right++;
    }
    return max;
}

int numSubarrayProductLessThanK(int* nums, int numsSize, int k) {
    int i, j;
    int tmp = 1;
    int left = 0, right = 0;
    int flag = 0;
    int count = 0;
    for (i = 0; i < numsSize; i++)
    {
        tmp = 1;
        flag = 0;
        if (left <= right)
        {
            tmp = 1;
            for (j = right; j >= left; j--)
            {
                tmp *= nums[j];
                if (tmp >= k)
                {
                    flag = 1;
                    break;
                }
                count++;
            }
            if (flag)
                left = j - 1;
        }
        right++;
    }
    return count;
}

struct ListNode* insertionSortList(struct ListNode* head) {
    if (!head)
        return head;

    ListNode* newhead, * newtail;
    newhead = newtail = (ListNode*)malloc(sizeof(ListNode));
    newhead->next = head;
    newtail = head;
    ListNode* prev;
    ListNode* cur = head->next;
    while (cur)
    {
        if (cur->val >= newtail->val)
            newtail = newtail->next;
        else {
            prev = newhead;
            while (prev->next->val <= cur->val)
                prev = prev->next;
            newtail->next = cur->next;
            cur->next = prev->next;
            prev->next = cur;
        }
        cur = newtail->next;
    }
    ListNode* ret = newhead->next;
    free(newhead);
    newhead = newtail = NULL;
    return ret;
}
int majorityElement(int* nums, int numsSize) {
    int ans = 0;
    for (int i = 0, count = 0; i < numsSize; i++)
    {
        if (nums[i] == ans)
            count++;
        else if (count == 0)
            ans = nums[i];
        else
            count--;
    }
    return ans;
}
uint32_t reverseBits(uint32_t n) {
    uint32_t ret = 0;
    for (int i = 0; i < 32; i++)
    {
        int tmp = n & 1;
        n >>= 1;
        ret = ret | tmp;
        if (i != 31)
            ret <<= 1;
    }
    return ret;
}

int hammingWeight(int n) {
    int count = 0;
    while (n)
    {
        n &= (n - 1);
        count++;
    }
    return count;
}

int main()
{
    int a[] = { 10,5,2,6 };
    int ret=reverseBits("11111111111111111111111111111101");
	return 0;
}